home *** CD-ROM | disk | FTP | other *** search
/ El Mac 9 / El Mac 9.iso / Shareware / Applications / MathPad 2.4 / Examples / spectrogram < prev    next >
Encoding:
Text File  |  1996-04-02  |  1.1 KB  |  34 lines  |  [TEXT/MPad]

  1. -- Create a frequency vs. time  spectrogram image.
  2. -- Requires Xfun "fft"
  3.  
  4. -- example parabolic freq sweep
  5. sweep(t) = cos(2*π*Radians*(.1+.015*t^2)*t)
  6.  
  7. ndata=512
  8. dt=1/30
  9. signal[i] = sweep(dt*(i-1)) dim[ndata]  -- sample it
  10.  
  11. Xmin=0;  Xmax=dt*ndata;  Xlabel="sec"
  12. plotline signal
  13.  
  14. -- use a sliding data window to see power spectrum changes
  15. -- "window" is the number of data points in the window
  16. -- "slide" is the number of data points to move the window for each spectra
  17.  
  18. spect(signal,window,slide)[i,j] = i0:=(i-1)*slide,
  19.       pwrspec(signal[i0+1:i0+window]) when j=1,,
  20.       transform[j]    dim[count(signal)/slide,window/2+1]
  21.  
  22. window=64    -- must be a power of 2
  23. slide:=trunc(window/4):
  24. -- show window and slide time on signal plot
  25. plotline {{0,window*dt},{-.93,-.93}} --{{x1,x2},{y1,y2}}
  26. plotline {{slide,slide+window}*dt,{-.9,-.9}}
  27.  
  28. newaxis
  29. Zmin=0; Zmax=.3
  30. Ymin:=-1/(window*dt):; Ymax:=1/(2*dt):; Ylabel:="  Hz":
  31. image  spect(signal,window,slide)
  32.  
  33. -- Note that when the window is moved by less than its width the last few spectra will be undefined because there is not a full window of data available.
  34.